
package com.insigma.business.qrcode.common.converter;



import com.insigma.business.qrcode.intell.dto.*;
import com.insigma.business.qrcode.intell.entity.CommonPolicyDO;
import org.springframework.beans.BeanUtils;

import java.util.List;


public class CommonPolicyProviderConverter extends AbstractConverter<CommonPolicyDTO, CommonPolicyDO> {

    private final static CommonPolicyProviderConverter commonPolicyConverter = new CommonPolicyProviderConverter();

    private CommonPolicyProviderConverter(){}

    
    public static CommonPolicyBSearcher convertRequestSO2Searcher(final CommonPolicySearchRequest request){
        final CommonPolicyBSearcher commonPolicyBSearcher = new CommonPolicyBSearcher(request.getPageNo(),
        request.getPageSize(),request.getSortKeyValueJoint());
        BeanUtils.copyProperties(request,commonPolicyBSearcher);
        return commonPolicyBSearcher;
    }

    public static List<CommonPolicyDTO> convertResponseDOList2DTOList(final List<CommonPolicyDO> commonPolicyDOList){
        return commonPolicyConverter.convertGenericResponseDOList2DTOList(commonPolicyDOList);
    }

    public static CommonPolicyDTO convertResponseDO2DTO(final CommonPolicyDO commonPolicyDO){
        return commonPolicyConverter.convertGenericResponseDO2DTO(commonPolicyDO);
    }
    public static CommonPolicyDO convertRequestUO2DO(final CommonPolicyUpdateRequest commonPolicyUpdateRequest) {
        final CommonPolicyDO commonPolicyDO = new CommonPolicyDO();
        BeanUtils.copyProperties(commonPolicyUpdateRequest,commonPolicyDO);

        return commonPolicyDO;
    }

    public static CommonPolicyDO convertRequestIO2DO(final CommonPolicyInsertRequest commonPolicyInsertRequest) {
        final CommonPolicyDO commonPolicyDO = new CommonPolicyDO();
        BeanUtils.copyProperties(commonPolicyInsertRequest,commonPolicyDO);
        return commonPolicyDO;
    }

    @Override
    protected CommonPolicyDTO doConvertResponseDO2DTO(CommonPolicyDO commonPolicyDO) {
        final CommonPolicyDTO commonPolicyDTO = new CommonPolicyDTO();
        try {
            BeanUtils.copyProperties(commonPolicyDO, commonPolicyDTO);
        }catch(RuntimeException be){

            return null;
        }
        return commonPolicyDTO;
    }
}
